package com.yu.newsSys.servlet;

import com.yu.newsSys.constants.ListenerConstants;
import com.yu.newsSys.utils.CommonUtils;
import com.yu.newsSys.vo.Result;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "online",urlPatterns = "/online")
public class OnlineServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 读取servletContext中的onlineList集合，并返回给前端显示
        ServletContext context = req.getServletContext();
        List<String> onlineList = (List<String>) context.getAttribute(ListenerConstants.ONLINE_LIST);
        CommonUtils.printData(Result.OK(onlineList),resp);
    }
}
